/*
 * Copyright (C) 2023 Coder.AN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include "realsense_camera.h"
#include "timer.h"
#include <unistd.h>

int main() try
{
    RealsenseCam cam;
    
    const char* depth_win = "depth_Image";
    cv::namedWindow(depth_win, cv::WINDOW_AUTOSIZE);
    const char* color_win = "color_Image";
    cv::namedWindow(color_win, cv::WINDOW_AUTOSIZE);

    while (cv::waitKey(1) && cvGetWindowHandle(depth_win))
    {
        cv::Mat color, depth;
        
        cam.get_all(color, depth);
        cv::imshow(depth_win, depth);
        cv::imshow(color_win, color);
    }

    return EXIT_SUCCESS;
}

catch (const rs2::error &e){
    std::cout<<"RealSense error calling"<<e.get_failed_function()<<"("<<e.get_failed_args()<<"):\n"
            <<e.what()<<std::endl;
    return EXIT_FAILURE;
}

catch (const std::exception &e){
    std::cout<<e.what()<<std::endl;
    return EXIT_FAILURE;
}